package com.example.app.runner;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author wangzhuangzhuang
 * @DESC:
 * @date 2022-02-10 10:03
 */
// ApplicationRunner: 参数被放入ApplicationArguments通过
// getOptionNames()、getOptionValues()、getSourceArgs()获取参数
@Slf4j
@Component
public class AppStartupRunner implements ApplicationRunner {

	@Override
	public void run(ApplicationArguments args) throws Exception {
		log.info("ApplicationRunner参数名称： {}", args.getOptionNames());
		log.info("ApplicationRunner参数值：{}", args.getOptionValues("age"));
		log.info("ApplicationRunner参数： {}", Arrays.toString(args.getSourceArgs()));
	}
}
